/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import com.bourre.data.collections.IndexedArray;
import com.bourre.data.iterator.Iterator;

import fever.data.file.FileFilter;
import fever.data.file.FileFilterCollection;
import fever.utils.Stringifier;

/**
 * Structure to store {@link FileFilter} object.
 *
 * @author Romain Ecarnot
 */
class fever.data.file.FileFilterList implements FileFilterCollection
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _list : IndexedArray;
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 * 
	 * @param filter A {@link fever.data.file.FileFilter}
	 * @param ... Another file filters
	 */
	public function FileFilterList( filter : FileFilter )
	{
		_list = new IndexedArray();
		
		var l : Number = arguments.length;
		for (var i : Number = 0; i < l; i++) 
		{
			_list.push( arguments[i] );
		}
	}
	
	/**
	 * Add passed-in {@code filter} to array.
	 * 
	 * @param filter {@link FileFilter} object to remove.
	 * @return {@code true} if the object has been successfully added.<br/>
	 * ( eq : wasn't already there )
	 */
	public function addFilter( filter : FileFilter ) : Boolean
	{
		return _list.push( filter );	
	}	
	
	/**
	 * Removes passed-in {@code filter} object from array.
	 * 
	 * @param filter {@link FileFilter} object to remove.
	 * @return {@code true} if the object has been found and was removed.
	 */
	public function removeFilter( filter : FileFilter ) : Boolean
	{
		return _list.remove( filter );
	}
	
	/**
	 * Test if passed-in {@code filter} is referenced in the array.
	 * 
	 * @param filter {@link FileFilter} object to check.
	 * @return {@code true} if object is referenced, otherwise {@code false}
	 */
	public function contains( filter : FileFilter ) : Boolean
	{
		return _list.objectExists( filter );	
	}
	
	/**
	 * Checks if array is empty.
	 */
	public function isEmpty() : Boolean
	{
		return _list.isEmpty();
	}
	
	/**
	 * Clear all list values.
	 */
	public function clear() : Void
	{
		_list.init();
	}
	
	/**
	 * Returns array iterator.
	 * 
	 * @return <strong>Pixlib ArrayIterator</strong> iterator.
	 */
	public function getFilterIterator() : Iterator
	{
		return _list.getIterator();	
	}
	
	/**
	 * Returns string representation.
	 */
	public function toString() : String
	{
		return Stringifier.parse( this );
	}
}